Loading data

We’re gonna look at NY NOAA data.

library(p8105.datasets)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6      ✔ purrr   0.3.4 
## ✔ tibble  3.1.7      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.0      ✔ stringr 1.4.0 
## ✔ readr   2.1.2      ✔ forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(plotly)
## Warning: package 'plotly' was built under R version 4.2.2
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout
data("ny_noaa")

ny_noaa_tidy =
  ny_noaa %>% 
  janitor::clean_names() %>% 
  separate(col = date, into = c('year','month','day'), sep = "-" , convert = TRUE) %>% 
  mutate(
     month = month.name[month],
     prcp = prcp / 10,
     tmax = as.numeric(tmax),
     tmin = as.numeric(tmin),
     tmax = tmax / 10,
     tmin = tmin / 10
  ) 

Plotly plots

Scatter plot

ny_noaa_tidy %>% 
  filter(month == c("January")) %>% 
  group_by(id, year, month) %>%
  mutate(text_label = str_c("year: ", year, "\nid:", id)) %>% 
  plot_ly(x = ~tmin, y = ~tmax, text = ~text_label,
          alpha = .5, type = "scatter", mode = "markers")
## Warning: Ignoring 93189 observations

boxplot

plot